
#include "ax_common.h"
#include "config.h"


unsigned short NetdConfig::out_port = 8883;
unsigned short NetdConfig::in_port = 8884;
unsigned int NetdConfig::max_connect = 1000;
int NetdConfig::max_inner = 50;
int NetdConfig::fps = 10;   //server frame rate
char NetdConfig::log_path[512] = "./";
char NetdConfig::log_name[128] = "netd.log";
char NetdConfig::log_debug_name[128] = "netd_debug.log";

int NetdConfig::reload_config(const char* file)
{
	int val, ret;
	const char *s;
	AxIniParser pconf;
	ret = pconf.parse(file);
	if (ret == -1) {
		ax_debug("file:%s not exist", file);
		return -1;
	} else if( ret == -2) {
		ax_debug("config file error. file=%s lineno= %d", file, pconf.get_error());
		return -1;
	}

	val = pconf.get_int("NET", "out_port");	
	if (val) NetdConfig::out_port = val;
	val = pconf.get_int("NET", "in_port");
	if (val) NetdConfig::in_port = val;	
	val = pconf.get_int("NET", "max_conn");
	if (val) NetdConfig::max_connect = val;
	val = pconf.get_int("SYS", "fps");
	if (val) NetdConfig::fps = val;

	s = pconf.get_string("SYS", "logpath");
	if (strlen(s) > 0) strncpy(NetdConfig::log_path, s, 512);
	s = pconf.get_string("SYS", "logname");
	if (strlen(s) > 0) strncpy(NetdConfig::log_name, s, 128);
	s = pconf.get_string("SYS", "debugname");
    if (strlen(s) > 0) strncpy(NetdConfig::log_debug_name, s, 128);
	return 0;
}


